#include <iostream>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10 ;
int a[N];
int n;
LL ans = -0x3f3f3f3f3f3f3f3f;

int main()
{
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	LL ret = 0;
	for(int i = 1; i <= n; i++)
	{
		ret += a[i];
		ans = max(ans, ret);
		if(ret < 0) ret = 0;
	}
	
	cout << ans << endl;
	
	return 0;
}
